const cloud = require('wx-server-sdk');
cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
});
const db = cloud.database()
// 新增用户
exports.main = async (event, context) => {
  const user = event.user
  user.user_type = user.open_id === 'oYAHL65-h9DwU6EIimiLis8PTFBo' ? '超级管理员' : '普通用户'

  const date = new Date();//当前时间
  const year = date.getFullYear() //返回指定日期的年份
  const month = date.getMonth() + 1;//月
  const day = date.getDate();//日
  const hour = date.getHours()+8;//时
  const minute = date.getMinutes();//分
  const second = date.getSeconds();//秒
    
    //当前时间 
    const curTime = year + "-" + month + "-" + day
            + " " + hour + ":" + minute + ":" + second;

  
  user.create_time  =curTime;
  return db.collection("sys_user").add({
    data: user
  })


};